package com.wise.aip.auth;

import java.util.HashMap;
import java.util.Map;

import com.wise.api.utils.HttpHelper;

public class GatewayAuth {
    private static final String APPLICATION_JSON = "application/json";

    private static final String APPLICATION_X_WWW_FORM_URLENCODED = "application/x-www-form-urlencoded";

    private static final int timeoutMillis = 60000;

    /**
     * gateway发送json参数POST请求
     * 
     * @param url
     * @param parm
     * @return
     * @throws Exception
     */
    public static String gatewayPostJson(String url, String param) throws Exception {
        Map headers = new HashMap(1);
        headers.put("Content-Type", APPLICATION_JSON);
        return HttpHelper.post(headers, param, url, timeoutMillis);
    }

    /**
     * gateway发送application/x-www-form-urlencoded参数POST请求
     * 
     * @param url
     * @param parm
     * @return
     * @throws Exception
     */
    public static String gatewayPost(String url, Map param) throws Exception {
        Map headers = new HashMap(1);
        headers.put("Content-Type", APPLICATION_X_WWW_FORM_URLENCODED);
        return HttpHelper.post(headers, param, url, timeoutMillis);
    }

    /**
     * gateway发送Get请求
     * 
     * @param url
     * @param parm
     * @return
     * @throws Exception
     */
    public static String gatewayGet(String url) throws Exception {
        Map headers = new HashMap(1);
        // headers.put("Content-Type", APPLICATION_JSON);
        // return HttpHelper.get(headers, url, timeoutMillis);
        return HttpHelper.get(url);
    }

}
